package com.ruoyi.web.webSocket;

import org.springframework.stereotype.Component;

import javax.websocket.server.ServerEndpoint;

import org.springframework.stereotype.Component;

import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.concurrent.ConcurrentHashMap;


@Component
@ServerEndpoint("/webSocket/{name}")
public class WebSocket {
    private static ConcurrentHashMap<String, WebSocket> webSocketConcurrentHashMap = new ConcurrentHashMap<>();
    @OnOpen
    public void onOpen(Session session, @PathParam(value = "name") String name){

        //默认客户端，没有重名

        System.out.println("【webSocket连接成功】当前连接人数为： 此人为：" + name);
    }

    @OnClose
    public void onClose(){

        //这里判断不周，仅实验用




        System.out.println("【webSocket退出成功】");
    }

    @OnError
    public void onError(Session session, Throwable throwable){

        System.out.println("error:");
        throwable.printStackTrace();
    }

    @OnMessage
    public void onMessage(Session session, String message) {

        System.out.println("【webSocket接收成功】内容为：" + message);
        //此处可以指定发送，或者群发，或者xxxx的

    }


}
